Package weasel.compiler.keywords

Source Code of weasel.compiler.keywords.WeaselKeyWordCompiler

package weasel.compiler.keywords;

import java.util.Arrays;
import java.util.ListIterator;

import weasel.compiler.WeaselCompiler;
import weasel.compiler.WeaselCompilerException;
import weasel.compiler.WeaselCompilerReturn;
import weasel.compiler.WeaselKeyWordCompilerHelper;
import weasel.compiler.WeaselToken;
import weasel.compiler.WeaselTokenType;

public abstract class WeaselKeyWordCompiler {
 
  public abstract WeaselCompilerReturn compile(WeaselToken token, WeaselCompiler compiler, WeaselKeyWordCompilerHelper compilerHelpher,  ListIterator<WeaselToken> iterator) throws WeaselCompilerException;

  protected void expect(WeaselToken token, WeaselTokenType...tokenTypes) throws WeaselCompilerException{
    for(int i=0; i<tokenTypes.length; i++){
      if(token.tokenType == tokenTypes[i]){
        return;
      }
    }
    throw new WeaselCompilerException(token.line, "Unexpected token %s expected %s", token, Arrays.toString(tokenTypes));
  }
 
  protected void expectFirst(WeaselToken token, boolean isFirst) throws WeaselCompilerException{
    if(!isFirst){
      throw new WeaselCompilerException(token.line, "Token %s has to be first", token);
    }
  }
 
}
TOP

Related Classes of weasel.compiler.keywords.WeaselKeyWordCompiler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.